package  
{
	import bulletbehavior.AccelerateRelativeBehavior;
	import bulletbehavior.AccelerateXYBehavior;
	import bulletbehavior.DieBehavior;
	import bulletbehavior.HomeTargetBehavior;
	import bulletbehavior.RotateBehavior;
	import bulletbehavior.SplitBehavior;
	import bulletbehavior.WaveBehaviorAngular;
	import turretbehavior.SpeedModulationBehavior;
	import turretbehavior.SpinningTurretBehavior;
	import turretbehavior.TypeCyclingTurretBehavior;
	import org.flixel.FlxG;
	/**
	 * ...
	 * @author morgan
	 */
	public class Stage7State extends GameState
	{
		
		[Embed (source = "../data/tutorial_rocks.png")] private var img_tut5:Class;
		
		public function Stage7State() 
		{
			levelName = "3-1";
			levelIndex = 6;
			chefName = "julienne";
			img_terrain = img_terrain_3;			
		}
		
		override public function setupBoss():void 
		{
			boss = new Boss(FlxG.width / 2 - 70, 10, 2);
			clouds2.color = 0x000000;
			clouds2.alpha = 0.5;
			
			var wavey:BulletPattern = new BulletPattern();
			wavey.addBehavior(new WaveBehaviorAngular(1, 360, 0.2));
			wavey.addBehavior(new AccelerateRelativeBehavior(20, 0));
			
			var straight:BulletPattern = new BulletPattern();
			
			var rotatey:BulletPattern = new BulletPattern();
			rotatey.addBehavior(new RotateBehavior(0, 90), 1.0, 6.0);
			
			var gravity:BulletPattern = new BulletPattern();
			gravity.addBehavior(new AccelerateXYBehavior(0, 50));
			
			var explodeRain:BulletPattern = new BulletPattern();
			explodeRain.addBehavior(new SplitBehavior(16, 20, 0, 360 * 15 / 16, gravity, -1), 1);
			
			var reverse:BulletPattern = new BulletPattern();
			reverse.addBehavior(new AccelerateRelativeBehavior( -25, 0), 0, 3.5);
			reverse.addBehavior(new RotateBehavior(180, 0), 3.5);
			reverse.addBehavior(new AccelerateRelativeBehavior( 40, 0), 3.5);
			reverse.addBehavior(new DieBehavior(), 6.3);
			
			var split:BulletPattern = new BulletPattern();
			split.addBehavior(new SplitBehavior(16, 95, -90, 90, reverse, -1));
			split.addBehavior(new DieBehavior());
			
			
			var home:BulletPattern = new BulletPattern();
			home.addBehavior(new HomeTargetBehavior(player, Math.PI / 2), 0, 2);
			
			var p1f:BossPattern = new BossPattern();
			var t1t:Turret = new Turret( -40, 0, straight, 4, 180, 120, 0.1);
			t1t.addBehavior(new SpinningTurretBehavior( -45, 90, true));
			var t2t:Turret = new Turret( 40, 0, straight, 4, 0, 120, 0.1);
			t2t.addBehavior(new SpinningTurretBehavior( 45, 90, true));
			var t3t:Turret = new Turret( -40, 0, straight, 4, 90, 120, 0.1);
			var t4t:Turret = new Turret( 40, 0, straight, 4, 90, 120, 0.1);
			
			var t5t:Turret = new Turret(0, 0, wavey, 0, 90, 80, 0.2);
			t5t.addBehavior(new TypeCyclingTurretBehavior(0.7, [0, 1, 2]));
			
			var t6t:Turret = new Turret(0, 0, rotatey, 0, 45, 100, 0.2);
			t6t.addBehavior(new TypeCyclingTurretBehavior(1.25, [0, 1, 2]));
			t6t.addBehavior(new SpeedModulationBehavior(4, 1.0));
			
			p1f.addTurretTime(0, 2, t1t);
			p1f.addTurretTime(0, 2, t2t);
			p1f.addTurretTime(2, Infinity, t3t);
			p1f.addTurretTime(2, Infinity, t4t);
			p1f.addTurretTime(2, 18, t5t);
			p1f.addTurretTime(18, Infinity, t6t);
			
			
			var p2f:BossPattern = new BossPattern();
			var t7t:Turret = new Turret(0, 70, straight, 4, -90, 75, 0.025);
			t7t.addBehavior(new SpinningTurretBehavior(30));
			
			var t8t:Turret = new Turret(0, 30, explodeRain, 0, 0, 50, 2.0);
			t8t.addBehavior(new TypeCyclingTurretBehavior(2.0, [2, 0, 1]));
			t8t.addBehavior(new SpinningTurretBehavior(-40));
			
			p2f.addTurretTime(0, Infinity, t7t);
			p2f.addTurretTime(2, Infinity, t8t);
			
			var p3f:BossPattern = new BossPattern();
			var t9t:Turret = new Turret(0, 10, split, Bullet.ROTTEN, 90, 1, 1.5);
			p3f.addTurretTime(0, Infinity, t9t);
			
			for (var i:int = 0; i < 4; i++)
			{
				var tt:Turret = new Turret( -100, 96 - i * 40, straight, 0, 0, 40, 1.0, true);
				tt.addBehavior(new TypeCyclingTurretBehavior(3.0, [i % 3, (i + 1) % 3, (i + 2) % 3]));
				p3f.addTurretTime(i, Infinity, tt);
			}
			
			var p4f:BossPattern = new BossPattern();
			for (i = 0; i < 7; i++)
			{
				tt = new Turret( (i - 3) * 40, -130, straight, 0, 90, 30, 0.5, true);
				tt.addBehavior(new TypeCyclingTurretBehavior(1.0, [i % 3, (i + 1) % 3, (i + 2) % 3]));
				p4f.addTurretTime(0, Infinity, tt);
			}
			for (var j:int = 0; j < 7; j++)
			{
				tt = new Turret( 100, (j - 3) * 40, straight, 0, 180, 30, 0.5, true);
				tt.addBehavior(new TypeCyclingTurretBehavior(2.0, [j % 3, (j + 1) % 3, (j + 2) % 3]));
				p4f.addTurretTime(0, Infinity, tt);
			}
			for (i = 0; i < 9; i++)
			{
				tt = new Turret(Math.cos(i * 6.2818 / 9) * 8, Math.sin(i * 6.2818 / 9) * 8, home, Bullet.ROTTEN, 0, 60, 4.0);
				tt.addBehavior(new SpinningTurretBehavior(20));
				p4f.addTurretTime(2, Infinity, tt);
			}

			
			boss.addState(new BossState(1800, p1f));
			boss.addState(new BossState(1200, p3f));
			boss.addState(new BossState(2000, p2f));
			boss.addState(new BossState(1700, p4f));
			
		}
		
		override public function update():void 
		{
			super.update();
			if (!Saving.showedRockTut && time < 1.5 && time + FlxG.elapsed >= 1.5)
			{
				showTutorial(img_tut5);
				Saving.showedRockTut = true;
			}
		}			
	}

}